<?php

namespace IDock\Insurance\JDAL\Response;

use IDock\Http\Response;

class AuthorizationTokenResponse extends AllJDALResponse
{
    public $token;

    public $expires;

    public function resolve(): Response
    {

        if (!$this->getBody()) {
            $this->setError('京东接口登录失败，请联系管理员');
        }

        return $this;
    }

    public function printerInit():Response
    {
        $JWT = $this->getBody();

        $this->token = $JWT;

        $JWTArr = explode('.',$JWT);

        if (isset($JWTArr[1])) {
            $JWTBody = json_decode(base64_decode($JWTArr[1]),true);
            $this->expires = $JWTBody['exp'] ?? '';
        }

        return $this;
    }

}
